import request from '@/utils/request'

// 主体信息接口
export interface Advertiser {
  id: number
  name: string
  code?: string
  status?: number
  createTime?: string
}

// 广告账户信息接口
export interface AdAccount {
  id: number
  name: string
  advertiserId: number
  accountId?: string
  status?: number
  balance?: number
  createTime?: string
}

// Mock数据服务（用于演示）
const mockAdvertisers: Advertiser[] = [
  { id: 1, name: '恒大地产 - 楼盘推广', code: 'HD001', status: 1 },
  { id: 2, name: '万科集团 - 品牌营销', code: 'WK002', status: 1 },
  { id: 3, name: '碧桂园 - 新盘预售', code: 'BGY003', status: 1 },
  { id: 4, name: '华润置地 - 高端社区', code: 'HR004', status: 1 },
  { id: 5, name: '保利发展 - 商业地产', code: 'BL005', status: 1 }
]

const mockAccounts: Record<number, AdAccount[]> = {
  1: [
    { id: 11, name: '恒大-信息流推广账户', advertiserId: 1, balance: 50000 },
    { id: 12, name: '恒大-搜索推广账户', advertiserId: 1, balance: 80000 },
    { id: 13, name: '恒大-视频推广账户', advertiserId: 1, balance: 30000 }
  ],
  2: [
    { id: 21, name: '万科-品牌曝光账户', advertiserId: 2, balance: 120000 },
    { id: 22, name: '万科-效果转化账户', advertiserId: 2, balance: 90000 }
  ],
  3: [
    { id: 31, name: '碧桂园-新房销售账户', advertiserId: 3, balance: 70000 },
    { id: 32, name: '碧桂园-客户获取账户', advertiserId: 3, balance: 60000 },
    { id: 33, name: '碧桂园-活动推广账户', advertiserId: 3, balance: 40000 }
  ],
  4: [
    { id: 41, name: '华润-高端推广账户', advertiserId: 4, balance: 150000 },
    { id: 42, name: '华润-精准投放账户', advertiserId: 4, balance: 100000 }
  ],
  5: [
    { id: 51, name: '保利-商业推广账户', advertiserId: 5, balance: 85000 },
    { id: 52, name: '保利-招商引流账户', advertiserId: 5, balance: 110000 },
    { id: 53, name: '保利-活动营销账户', advertiserId: 5, balance: 55000 }
  ]
}

// 模拟延时函数
const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))

// 获取主体列表
export const getAdvertiserList = async () => {
  // 模拟网络延时
  // await delay(800)
  
  // // 模拟API响应格式
  // return {
  //   data: mockAdvertisers,
  //   code: 200,
  //   message: '获取成功'
  // }
  
  // 真实环境下使用以下代码
  return request.get({ url: '/ads.tencent_advertising_account/allLists' })
}

// 根据主体ID获取广告账户列表
export const getAdAccountsByAdvertiserId = async (advertiserId: number) => {
  // 模拟网络延时
  // await delay(600)
  
  // // 模拟API响应格式
  // return {
  //   data: mockAccounts[advertiserId] || [],
  //   code: 200,
  //   message: '获取成功'
  // }
  
  // 真实环境下使用以下代码
  return request.get({ url: `/ads.tencent_advertising_user_ad/allLists?account_id=${advertiserId}` })
}

// 获取主体详情
export const getAdvertiserDetail = (id: number) => {
  return request.get({ url: `/api/advertiser/${id}` })
}

// 获取账户详情
export const getAdAccountDetail = (id: number) => {
  return request.get({ url: `/api/ad-account/${id}` })
} 